翻訳と辞書
Words near each other
・ Augment
・ Augment (app)
・ Augment (linguistics)
・ Augmentation (algebra)
・ Augmentation (music)
・ Augmentation (pharmacology)
・ Augmentation ideal
・ Augmentation industries
・ Augmentation of Benefices Act 1665
・ Augmentation of Benefices Act 1677
・ Augmentation of honour
・ Augmentation pharyngoplasty
・ Augmentation Research Center
・ Augmentative
・ Augmentative and alternative communication
Augmented assignment
・ Augmented Backus–Naur Form
・ Augmented browsing
・ Augmented cognition
・ Augmented Dickey–Fuller test
・ Augmented dodecahedron
・ Augmented fifth
・ Augmented GeoTravel
・ Augmented hexagonal prism
・ Augmented Lagrangian method
・ Augmented learning
・ Augmented major seventh chord
・ Augmented matrix
・ Augmented ninth chord
・ Augmented octave


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Augmented assignment : ウィキペディア英語版
Augmented assignment

Augmented assignment (or compound assignment) is the name given to certain
assignment operators in certain programming languages (especially those derived from C). An augmented assignment is generally used to replace a statement where an operator takes a variable as one of its arguments and then assigns the result back to the same variable. A simple example is x += 1 which is expanded to x = x + 1. Similar constructions are often available for various binary operators.
In general, in languages offering this feature, most operators that can take a variable as one of their arguments and return a result of the same type have an augmented assignment equivalent that assigns the result back to the variable in place, including arithmetic operators, bitshift operators, and bitwise operators.
==Discussion==
For example, the following statement or some variation of it can be found in many programs:
x = x + 1
This means "find the number stored in the variable ''x'', add 1 to it, and store the result of the addition in the variable ''x''." As simple as this seems, it may have an inefficiency, in that the location of variable ''x'' has to be looked up twice if the compiler does not recognize that two parts of the expression are identical: ''x'' might be a reference to some array element or other complexity. In comparison, here is the augmented assignment version:
x += 1
With this version, there is no excuse for a compiler failing to generate code that looks up the location of variable ''x'' just once, and modifies it in place, if of course the machine code supports such a sequence. For instance, if x is a simple variable, the machine code sequence might be something like
Load x
Add 1
Store x
and the same code would be generated for both forms. But if there is a special op code, it might be
MDM x,1
meaning "Modify Memory" by adding 1 to x, and a decent compiler would generate the same code for both forms. Some machine codes offer INC and DEC operations (to add or subtract one), others might allow constants other than one.
More generally, the form is
x ?= expression
where the ? stands for some operator (not always +), and there may be no special op codes to help. There is still the possibility that if ''x'' is a complicated entity the compiler will be encouraged to avoid duplication in accessing ''x'', and of course, if ''x'' is a lengthy name, there will be less typing required. This last was the basis of the similar feature in the ALGOL compilers offered via the Burroughs B6700 systems, using the tilde symbol to stand for the variable being assigned to, so that
LongName:=x + sqrt(LongName)
*7;
would become
LongName:=x + sqrt(~)
*7;
and so forth. This is more general than just ''x:=~ + 1;'' Producing optimum code would remain the province of the compiler.

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Augmented assignment」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.